package com.hotdog.controller;

import com.alipay.api.AlipayApiException;
import com.hotdog.pojo.PayInfo;
import com.hotdog.service.PayUserService;
import com.hotdog.vo.SysResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;


/**
 * 接收支付请求 并响应支付连接
 * @author 郭鲁政
 */
@RestController
@RequestMapping("/alipay")
@Slf4j
@PreAuthorize("hasAuthority('sys:res:list')")
public class AliPayController {

    @Autowired
   private PayUserService payUserService;
    @GetMapping("payOrder/{moeny}")
    public SysResult geturl(@PathVariable String moeny) throws AlipayApiException {
        PayInfo.money=moeny;
        if (!moeny.equals("9999")){
            return SysResult.fail();
        }
        String s = UUID.randomUUID().toString();
        PayInfo.orderId=s;
        String payInfo = payUserService.getPayInfo(s);
        if (payInfo==null){
            return SysResult.fail();
        }
        return SysResult.success(payInfo);
    }
    @GetMapping("/logs")
    public void logs(){
        payUserService.logs();
    }

}
